import request from './http'
function getSongList(type,size=20,offset=0){
    const url=`/aos/v1/restserver/ting/baidu.ting.billboard.billList?method=baidu.ting.billboard.billList&type=${type}&size=${size}&offset=${offset}`
    return request.get(url)
}
function getMusicPlay(songid){
    let url=`/aos/v1/restserver/ting?method=baidu.ting.song.play&songid=${songid}`
    return request.get(url)
}
// 轮播图
function getSwiper (pageNum=1, pageSize=4) {
    const params = new URLSearchParams();
    params.append("pageNum", pageNum);
    params.append("pageSize", pageSize);
    const url = `/api/cms/article/open/banner/list`
    return request.post(url, params)
}
// 新闻列表
function newsList (pageNum=1, pageSize=18) {
    const params = new URLSearchParams();
    params.append("pageNum", pageNum);
    params.append("pageSize", pageSize);
    const url = `/api/cms/category/open/list`
    return request.post(url, params)
}
//收藏功能
function getCollect(articleId) {
    const url = `/api/cms/collect/collect/article/${articleId}`;
    return request.get(url)
}
//收藏列表
function getCollectList() {
    const url = `/api/cms/article/collect/list`;
    return request.get(url);

}
//增加阅读量
function addSee(id) {
    const url = `/api/cms/article/open/add/read-num/${id}`;
    return request.get(url);

}
//点赞
function getZan(articleId) {
    const url = `/api/cms/article/add/zan/${articleId}`;
    return request.get(url);
}
// 新闻订阅
function newsOrder (categoryIds) {
    const params = new URLSearchParams();
    params.append("categoryIds", categoryIds);
    const url = `/api/cms/userCategory/subscription/category`
    return request.post(url, params)
}
// 订阅列表
function orderList(){
    let url=`/api/cms/category/subscription/list`
    return request.get(url)
}
// 新闻详情
function newDetail(pageNum=1, pageSize=1000,categoryId=2) {
    const params = new URLSearchParams();
    params.append("pageNum", pageNum);
    params.append("pageSize", pageSize);
    params.append("categoryId", categoryId);
    const url = `/api/cms/article/open/list`
    return request.post(url, params)
}
// 文章详情
function article(articleId) {
    const url = `/api/cms/article/open/detail/${articleId}`
    return request.get(url)
}
//登录接口
function loginDetail(username,password,rememberMe){
    const params = new URLSearchParams();
    params.append("username", username);
    params.append("password", password);
    params.append("rememberMe", rememberMe);
    const url = `/api/login`
    return request.post(url,params)
}
// 退出登录
function  logout() {
    const url = `/api/logout`
    return request.get(url)

}

//注册
function  userRegis(loginName,code,phonenumber,password,userName){
    const params =new URLSearchParams();
    params.append("loginName",loginName);
    params.append("code",code);
    params.append("phonenumber",phonenumber);
    params.append("password",password);
    params.append("userName",userName);
    const url=`/api/registry`
    return request.post(url,params)
}
//手机验证码
function phone(mobile){
    let url=`/api/short-message/vcode/${mobile}`
    return request.get(url)
}

//忘记密码
function forgetPassword(loginName,password,phonenumber,code){
    const params =new URLSearchParams();
    params.append("loginName",loginName);
    params.append("password",password);
    params.append("phonenumber",phonenumber);
    params.append("code",code);
    const  url=`/api/password/forget`;
    return request.post(url,params)
}

//用户信息
function userInfo(){
    let url=`/api/login-user/info`
    return request.get(url)

}

//修改头像
function avatar (avatarfile){
    const params =new FormData();
    params.append("avatarfile",avatarfile);
    const  url=`/api/system/user/profile/update/avatar/nos`;
    return request.post(url,params)
}
//修改个人信息
function changemine(userName,email,phonenumber,sex,remark){
    const params =new URLSearchParams();
    params.append("userName",userName);
    params.append("email",email);
    params.append("phonenumber",phonenumber);
    params.append("sex",sex);
    params.append("remark",remark);
    const  url=`/api/system/user/profile/update`;
    return request.post(url,params)
}
// 搜索接口
function getsearch(title,pageNum=1, pageSize=30) {
    const params = new URLSearchParams();
    params.append("pageNum", pageNum);
    params.append("pageSize", pageSize);
    params.append("title", title);
    const url = `/api/cms/article/open/list`
    return request.post(url, params)
}
//热点新闻
function hotNews(pageNum = 1, pageSize = 10) {
    const params = new URLSearchParams();
    params.append("pageNum", pageNum);
    params.append("pageSize", pageSize);
    const url = `/api/cms/article/open/hot/list`
    return request.post(url, params)
}
export {hotNews,getsearch,addSee,getZan,getCollect,getCollectList,article,changemine,avatar,orderList,newsOrder,getSongList,getMusicPlay,getSwiper,newsList,newDetail,loginDetail,logout,userRegis,phone,forgetPassword,userInfo}



